package org.zdc.damasteel.manager;
import org.zdc.damasteel.skin.ComponentSkin;
import org.zdc.damasteel.Component;
import nme.ObjectHash;
using org.zdc.utils.Helper;

class SkinManager 
{
	private static var comp2SkinMap:ObjectHash<Class<Component>, Class<ComponentSkin>> = new ObjectHash<Class<Component>, Class<ComponentSkin>>();
	private static var skin2CompMap:ObjectHash<Class<ComponentSkin>, Class<Component>> = new ObjectHash<Class<ComponentSkin>, Class<Component>>();
	
	/**
	 * 获取皮肤类支持的属性列表
	 * @return
	 */
	public static function getAllSupportStyles(sc:Class<ComponentSkin>):Array<String>{
		var allStyles = new Array<String>();
		
		//皮肤的继承
		var clses:Array < Class < ComponentSkin >> = sc.getInheritClasses(ComponentSkin);	
		for (cls in clses) {	
			allStyles = allStyles.concat(untyped Reflect.callMethod(null, Reflect.getProperty(cls, "getSpecifiedStyles"), []));
		}
		
		return allStyles;
	}
	
	/**
	 * 设置皮肤关联的关系
	 * @param	c
	 * @param	k
	 */
	public static function mapSkinToComponent(c:Class<Component>, k:Class<ComponentSkin>):Void {
		comp2SkinMap.set(c, k);
		skin2CompMap.set(k, c);
	}
	
	/**
	 * 获取皮肤类关联的组件类
	 * @param	k
	 * @return
	 */
	public static function getComponentClass(k:Class<ComponentSkin>):Class<Component> {
		return skin2CompMap.get(k);
	}
	
	/**
	 * 获取组件关联的皮肤类
	 * @param	c
	 * @return
	 */
	public static function getSkinClass(c:Class<Component>):Class<ComponentSkin> {
		return comp2SkinMap.get(c);
	}
}